package com.flight.view;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;

public class LoginFrame extends JFrame {
    private JTextField passengerIdField; // 身份证号输入框
    private JPasswordField passwordField; // 密码输入框
    private JButton loginBtn; // 登录按钮

    public LoginFrame() {
        initUI();
    }

    private void initUI() {
        setTitle("用户登录");
        setSize(300, 200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        JPanel panel = new JPanel(new GridLayout(3, 2, 10, 10));
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        panel.add(new JLabel("身份证号："));
        passengerIdField = new JTextField();
        panel.add(passengerIdField);

        panel.add(new JLabel("密码："));
        passwordField = new JPasswordField();
        panel.add(passwordField);

        loginBtn = new JButton("登录");
        panel.add(loginBtn);

        add(panel);
    }

    // 提供getter方法获取输入值
    public String getPassengerId() {
        return passengerIdField.getText().trim();
    }

    public String getPassword() {
        return new String(passwordField.getPassword()).trim(); // 注意：密码字段是char[]
    }

    // 绑定登录按钮事件
    public void addLoginListener(ActionListener listener) {
        loginBtn.addActionListener(listener);
    }
}